﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Addin665.Frms {
    public partial class MultiGetSetCfgFrm : Form {
        public MultiGetSetCfgFrm() {
            InitializeComponent();
        }

        private void MultiGetSetCfgFrm_Load(object sender, EventArgs e) {
            string fullPath = System.Reflection.Assembly.GetAssembly(typeof(Connect)).Location;
            string tplFile = System.IO.Path.GetDirectoryName(fullPath) + @"\Data" + @"\MultiGetSetTpl.txt";

            if (File.Exists(tplFile)) {
                string txt = null;
                txt = CommonHelp.FileHelper.ReadFile(tplFile);
                //txt = txt.Replace("<?PropertyClass>", "$T");
                //txt = txt.Replace("<?privateName>", "$_A");
                //txt = txt.Replace("<?PropertyName>", "$A");
                this.textBox1.Text = txt;
            }
        }

        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
            if (e.Node.Tag != null && e.Node.Tag.ToString() == "0") {
                return;
            }

            InputFrm frm = new InputFrm();
            if (frm.ShowDialog(this) != System.Windows.Forms.DialogResult.OK) {
                return;
            }
            if (!string.IsNullOrEmpty(frm.InputText.Trim())) {
                e.Node.Text = frm.InputText;
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e) {
            string fullPath = System.Reflection.Assembly.GetAssembly(typeof(Connect)).Location;
            string tplFile = System.IO.Path.GetDirectoryName(fullPath) + @"\Data" + @"\MultiGetSetTpl.txt";
            string dir = System.IO.Path.GetDirectoryName(tplFile);
            if (!Directory.Exists(dir)) {
                System.IO.Directory.CreateDirectory(dir);
            }
            if (!File.Exists(tplFile)) {
                using (System.IO.File.AppendText(tplFile)) { }
            }

            using (StreamWriter sw = new StreamWriter(tplFile)) {
                StringBuilder sb = new StringBuilder(this.textBox1.Text); 
                sw.Write(sb.ToString());
                sw.Flush();
            }
        } 
    }
}
